package com.ruoyi.web.controller.other;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.property.domain.HousePropertyT;
import com.ruoyi.property.service.IHousePropertyTService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物业公司Controller
 * 
 * @author ruoyi
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/other/property")
public class HousePropertyTController extends BaseController
{
    @Autowired
    private IHousePropertyTService housePropertyTService;
    @Autowired
    private ISysUserService userService;

    /**
     * 查询物业公司列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HousePropertyT housePropertyT)
    {
        startPage();
        List<HousePropertyT> list = housePropertyTService.selectHousePropertyTList(housePropertyT);
        return getDataTable(list);
    }

    /**
     * 导出物业公司列表
     */
     @Log(title = "物业公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HousePropertyT housePropertyT)
    {
        List<HousePropertyT> list = housePropertyTService.selectHousePropertyTList(housePropertyT);
        ExcelUtil<HousePropertyT> util = new ExcelUtil<HousePropertyT>(HousePropertyT.class);
        util.exportExcel(response, list, "物业公司数据");
    }

    /**
     * 获取物业公司详细信息
     */
    @GetMapping(value = "/{propertyId}")
    public AjaxResult getInfo(@PathVariable("propertyId") Long propertyId)
    {
        return AjaxResult.success(housePropertyTService.selectHousePropertyTByPropertyId(propertyId));
    }

    /**
     * 新增物业公司
     */
    @Log(title = "物业公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HousePropertyT housePropertyT)
    {

        housePropertyT.setCreater(getUsername());
        return toAjax(housePropertyTService.insertHousePropertyT(housePropertyT));
    }

    /**
     * 修改物业公司
     */
    @Log(title = "物业公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HousePropertyT housePropertyT)
    {
        return toAjax(housePropertyTService.updateHousePropertyT(housePropertyT));
    }

    /**
     * 删除物业公司
     */
    @Log(title = "物业公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{propertyIds}")
    public AjaxResult remove(@PathVariable Long[] propertyIds)
    {
        return toAjax(housePropertyTService.deleteHousePropertyTByPropertyIds(propertyIds));
    }
}
